﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Globalization;
using Libs.Partner;

public partial class Pages_Partners_Partner_Add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AppUtils.CheckLogin();
        Title = Title + " - Thêm mới đối tác";
        if (!IsPostBack)
        {
            init();
        }
    }

    private void init()
    {
        // DropDownList
        var _Company = new Company();
        drpCompany.DataSource = _Company.GetTList();
        drpCompany.DataBind();
        drpCompany.Items.Insert(0, new ListItem("Chọn cơ quan, đơn vị:", "0"));
    }

    protected void btAdd_Click(object sender, EventArgs e)
    {
        var _Partner = new Partner();
        _Partner.FullName = txtFullName.Text.Trim();
        _Partner.CompanyID = Convert.ToInt32(drpCompany.SelectedValue);
        _Partner.Position = txtPosition.Text;
        _Partner.Email = txtEmail.Text.Trim().ToLower();
        _Partner.Fax = txtFax.Text.Trim();
        _Partner.Mobile = txtMobile.Text.Trim();
        _Partner.WorkPhone = txtWorkPhone.Text.Trim();
        _Partner.HomePhone = txtHomePhone.Text.Trim();
        _Partner.HomeAddress = txtHomeAddress.Text.Trim();
        _Partner.WorkAddress = txtWorkAddress.Text.Trim();
        _Partner.Website = txtWebsite.Text.Trim().ToLower();
        _Partner.Description = txtDescription.Text.Trim();

        if (txtBirthday.Text.Trim().Length > 0)
        {
            try
            {
                _Partner.Birthday = Convert.ToDateTime(txtBirthday.Text, new CultureInfo("vi-VN"));
            }
            catch
            {
                Message.Alert(Page, "Ngày sinh nhập không đúng!");
                return;
            }
        }
        _Partner.FullNameEn = Partner.UCS2Lower(_Partner.FullName);

        _Partner.Add();
        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.PartnerList);
    }

    protected void btCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect(Constant.ADMIN_PATH + Resources.Url.PartnerList);
    }
}
